Open Application Event
Open Application Event
When the user opens your application, the Finder uses the
Process Manager to launch your application. On startup, your application
typically performs any needed initialization, and then begins to process
events. If your application supports high-level events, your application
receives the Open Application event.
To handle the Open Application event, your application should do just
what the user expects it to do when your application is opened. For example,
your application might open a new untitled window in response to an
Open Application event.
The program below shows a handler that processes the Open Application
event. The Open Application event does not have any required parameters.
This handler first calls an application- defined function called
MyGotRequiredParams. See Writing Apple Event Handlers for a
listing of MyGotRequiredParams. This function checks to see if the Apple
event contains any required parameters. By definition, the Open Application
event should not contain any required parameters so, if the Apple event does
contain any, the handler returns an error. Otherwise the handler opens a new
document window.
// A handler for the Open Application event
// Assuming inclusion of
#include <AppleEvents.h>
pascal OSErr MyHandleOAPP (AppleEvent * theAppleEvent,
AppleEvent * reply, long handlerRefcon);
OSErr MyGotRequiredParams (AppleEvent * theAppleEvent);
void DoNew (void);
pascal OSErr MyHandleOAPP(AppleEvent * theAppleEvent,
AppleEvent * reply, long handlerRefcon)
{
OSErr myErr;
myErr = MyGotRequiredParams( theAppleEvent);
if ( myErr)
return myErr;
else {
DoNew();
return noErr;
}
}
The MyGotRequiredParams function checks that all required parameters
have been extracted from the Apple event.